//
//  NFSPDFWebView.m
//  NetEaseFinancial
//
//  Created by 孙玉建 on 16/3/3.
//  Copyright © 2016年 吴玉峰. All rights reserved.
//

#import "NFSPDFWebView.h"

@interface NFSPDFWebView()

@property (nonatomic, strong) UIView *baseView;

@end

@implementation NFSPDFWebView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {

    }
    return self;
}

- (void)initWithWebViewUrl:(NSString *)urlStr baseView:(UIView *)baseView {
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]];

    [self setUserInteractionEnabled:YES]; //是否支持交互

    self.opaque = NO ;           // opaque是不透明的意思
    self.scalesPageToFit = YES; //自动缩放以适应屏幕
    [self loadRequest:request];

    UIButton *dismissBtn = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 80, 30, 60, 40)];
    [dismissBtn setTitle:@"关闭" forState:UIControlStateNormal];
    [dismissBtn addTarget:self action:@selector(dismissBtnClick) forControlEvents:UIControlEventTouchUpInside];

    [dismissBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    dismissBtn.titleLabel.font = [UIFont systemFontOfSize:18.f];
    [self addSubview:dismissBtn];
    [baseView addSubview:self];
}

- (void)initWithWebViewUrlAndRemoveBaseView:(NSString *)urlStr baseView:(UIView *)baseView {
    self.baseView = baseView;
    self.backgroundColor = [UIColor whiteColor];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]];

    [self setUserInteractionEnabled:YES]; //是否支持交互
    self.opaque = NO ;           // opaque是不透明的意思
    self.scalesPageToFit = YES; //自动缩放以适应屏幕
    [self loadRequest:request];

    UIButton *dismissBtn = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width - 80, 30, 60, 40)];
    [dismissBtn setTitle:@"关闭" forState:UIControlStateNormal];
    [dismissBtn addTarget:self action:@selector(baseViewDissmiss) forControlEvents:UIControlEventTouchUpInside];
    // dismissBtn.backgroundColor = [UIColor  redColor];
    [dismissBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    dismissBtn.titleLabel.font = [UIFont systemFontOfSize:18.f];
    [self addSubview:dismissBtn];
    [baseView addSubview:self];
}

- (void)dismissBtnClick {
    [self removeFromSuperview];
}

- (void)baseViewDissmiss {
    [self dismissBtnClick];
    [self.baseView removeFromSuperview];
}


@end
